#include "MyTimer.h"

CMyTimer* CMyTimer::NewL(MTimerCallback* callback, int eventid, int extrapara) 
{
	CMyTimer* self = CMyTimer::NewLC(callback, eventid, extrapara); 
	CleanupStack::Pop(self); 
	return self;
}
CMyTimer* CMyTimer::NewLC(MTimerCallback* callback, int eventid, int extrapara)
{
	CMyTimer* self = new (ELeave) CMyTimer(callback, eventid, extrapara); 
	CleanupStack::PushL(self); 
	self->ConstructL(); 
	return self;
}

void CMyTimer::ConstructL() 
{
	User::LeaveIfError(iTimer.CreateLocal());
	status = KErrNone;
	CActiveScheduler::Add(this);
}

//extrapara?ontimer????callback,????????ontimer????
CMyTimer::CMyTimer(MTimerCallback* callback, int eventid, int extrapara) 
	: m_callback(*callback), m_eventid(eventid), CActive(0) 
{
	m_interval = 1000000;//default delay is 1 second
	m_extrapara = extrapara;
	m_nTest = 0;
}

CMyTimer::~CMyTimer()
{
	iTimer.Close();
	Cancel(); 
}

void CMyTimer::StartAO()
{ 
	status = KRequestPending;

	iTimer.After(iStatus, m_interval);
	SetActive();
}

void CMyTimer::RunL() 
{ 
	m_nTest ++;
	CMyTimer::StartAO(); 
	m_callback.OnTimer(this, m_eventid, m_extrapara);
}

void CMyTimer::Activate() 
{
	CMyTimer::StartAO(); 
}

void CMyTimer::DoCancel() 
{ 
	iTimer.Cancel();
}
